package com.hl.web;

import com.hl.pojo.Users;
import com.hl.service.UserService;
import com.hl.util.GeneralResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/zhuce")
    public GeneralResult zhuce(@RequestBody Users users){
        int num = userService.add(users);
        if (num>0){
            return GeneralResult.success("添加成功");
        }else{
            return GeneralResult.fail();
        }
    }

    @RequestMapping("/selectuser")
    public GeneralResult selectUser(@RequestBody Map<String,String> map){
        String keyword = map.get("keyword");
        System.out.println(userService.findAll(keyword));
        return GeneralResult.success(userService.findAll(keyword));
    }
}
